<template>
	<view class="order-detail-page">
		<view class="content">
			<view class="address-section">
				<view class="order-content"
					v-if="[11,12,13,14,15].includes(orderDetail.ProductType) && [15,20].includes(orderDetail.Type)">
					<view class="qrcode-wap">
						<!-- HJ20220201 <canvas id="qrcode" canvas-id="qrcode" style="width: 200px;height: 200px;" />-->
						<!-- <canvas id="qrcode" canvas-id="qrcode" style="width: 200px;height: 200px;" /> -->
<!-- 												<view class="title">
							预约成功,请{{orderDetail.OrdersOnlineInfoViewList[0].OrderDate}}刷身份证入园！
						</view> -->
<!-- 												<view class="title">
							预约成功,请{{orderDetail.ContactPerson}}刷身份证入园！
						</view> -->
					</view>
				</view>
				<view class="wapper" v-else>
					<view class="img">
						<image src="../../static/images/27.png" mode=""></image>
					</view>
					<view class="desc">
						{{statusTitle}}
					</view>
				</view>
				<image class="a-bg"
					src="">
				</image>
			</view>
			<view class="title">
				商品信息
			</view>
			<view class="goods-section">
				<view class="g-item" v-for="(item,index) in orderDetail.OrdersOnlineInfoViewList" :key="index"
					@click="navGoToDetail(item.ProductId,item.ProductType)">
					<image :src="item.Img"></image>
					<view class="right">
						<text class="g-title clamp">{{item.ProductName}}</text>
						<view class="wapper"><text class="price">￥{{item.SalePrice }}</text></view>
						<view class="spec">数量：x{{item.Num}}</view>
						<view class="spec">{{item.ProductSpecStr}}</view>
					</view>
				</view>
				<!-- 订单商品信息 -->
				<view class="price-box">
					<text class="num">订单总价</text>
					<text class="price">{{orderDetail.SalePriceTotal}}</text>
				</view>
			</view>
			<view class="title">
				订单信息
			</view>
			<view class="order-section">
				<view class="order-info">
					<!-- <view class="item">
						<view class="name">订单失效时间：</view><view class="value">{{orderDetail.OrdersANO}}</view>
					</view> -->
					<view class="item">
						<view class="name">订单编号：</view>
						<view class="value">{{orderDetail.OrdersANO || ''}}
							<text v-if="orderDetail.OrdersANO" @click="copyCode(orderDetail.OrdersANO)"
								class="xicon icon-copy"></text>
						</view>
					</view>
					<view class="item">
						<view class="name">备注：</view>
						<view class="value">{{orderDetail.OrdersOnlineInfoViewList[0].OrderRemak || '无'}}</view>
					</view>
					<view class="item">
						<view class="name">下单时间：</view>
						<view class="value">{{orderDetail.AddTime}}</view>
					</view>
					<!--
					<view class="item">
						<view class="name">商品规格：</view><view class="value">{{orderDetail.OrdersOnlineInfoViewList[0].ProductSpecStr || ''}}</view>
					</view>
					<view class="item">
						<view class="name">开始时间：</view><view class="value">{{orderDetail.OrdersOnlineInfoViewList[0].UseStartTime || ''}}</view>
					</view>
					<view class="item">
						<view class="name">结束时间：</view><view class="value">{{orderDetail.OrdersOnlineInfoViewList[0].UseEndTime || '无'}}</view>
					</view>-->
					<view class="item" v-if="orderDetail.ProductType === 13">
						<view class="name">预定时间：</view>
						<view class="value">
							{{orderDetail.OrdersOnlineInfoViewList[0].CheckInDate || ''}}~{{orderDetail.OrdersOnlineInfoViewList[0].CheckOutDate || ''}}
						</view>
					</view>
					<!-- <view class="item">
						<view class="name">支付方式：</view><view class="value">{{detail.order_num}}</view>
					</view> -->
				</view>
			</view>
			<canvas v-if="orderDetail.ProductType === 11 || orderDetail.ProductType === 16" id="qrcode"
				canvas-id="qrcode" style="width: 200px;height: 200px;margin: 0 auto;"></canvas>

			<view class="title" v-if="detail.Type===1">
				物流信息
			</view>
			<view class="order-section" v-if="detail.Type===1">
				<view class="order-info">
					<view class="item">
						<view class="name">物流名称：</view>
						<view class="value">{{Logistics.LogisticsName || ''}}</view>
					</view>
					<view class="item">
						<view class="name">物流单号：</view>
						<view class="value">{{Logistics.LogisticsANO || '无'}}</view>
					</view>
					<view class="item">
						<view class="name">备注：</view>
						<view class="value">{{Logistics.Remark || ''}}</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		mapState,
		mapMutations,
		mapActions
	} from 'vuex'
	import {
		getLogistics
	} from '@/api/mall.js'
	// import uQRCode from '@/components/uqrcode/common/uqrcode.js'
		import UQRCode from "uqrcodejs"
	import {
		orderStateExp
	} from '@/utils/base.js'
	import {
		Tools
	} from '@/utils/tools.js'
	export default {
		data() {
			return {
				detail: {},
				Logistics: {},
				goodsList: [], //购买商品信息
				statusArr: [1, 2, 3, 6, 7, 10], // 显示退款状态  1.待发货 2.已发货 3.运输中 6.已收货 7.发货失败 10.退款失败
			}
		},
		computed: {
			...mapState({
				orderDetail: state => state.shop.orderDetail,
			}),
			statusTitle() {
				let status = this.orderDetail.Type
				let data = orderStateExp(status)
				return data.stateTip
			},
		},
		filters: {
			goodsImage(e) {
				let arr = JSON.parse(e) || []
				return arr[0]
			},
			toFixd(e) {
				let price = e * 1 || 0
				return price.toFixed(2)
			}
		},
		onLoad() {
			uni.setNavigationBarTitle({
				title: '订单详情'
			});
			this.detail = this.orderDetail
			console.log(6669, this.orderDetail)
			this.loadQRCode()

			if (this.detail.Type === 1) {
				this.loadLogistics()
			}
		},
		methods: {
			...mapMutations(['setRefund']),
			async loadLogistics() {
				try {
					const {
						Data
					} = await getLogistics({
						Id: this.detail.Id
					})
					this.Logistics = Data[0]
				} catch (e) {
					//TODO handle the exception
				}
			},
			loadQRCode() {
				let qrOCode = this.orderDetail.OrdersOnlineInfoViewList[0].Code;
				if (qrOCode.includes("OrdersInfo")) {
					var qr = new UQRCode();
					if (qrOCode) {
						// 设置二维码内容
						qr.data = qrOCode;
						// 设置二维码大小，必须与canvas设置的宽高一致
						qr.size = 200;
						// 调用制作二维码方法
						qr.make();
						// 获取canvas上下文
						var canvasContext = uni.createCanvasContext('qrcode', this); // 如果是组件，this必须传入
						// 设置uQRCode实例的canvas上下文
						qr.canvasContext = canvasContext;
						// 调用绘制方法将二维码图案绘制到canvas上
						qr.drawCanvas();
					}
				}
			},
			// 前往退款页面
			navToRefund(item) {
				this.setRefund({
					...item,
					order_num: this.detail.order_num
				})
				let url = `/pages/order/createRefund`
				uni.redirectTo({
					url
				})
			},
			copyCode(text) {
				console.log('00', text)
				let _this = this
				if (text) {
					wx.setClipboardData({
						data: text,
						success: function(res) {
							wx.showToast({
								title: '复制成功',
								duration: 1000
							})
							wx.getClipboardData({
								success: function(res) {}
							})
						}
					});
				}
			},
			// 跳转商品详情页
			navGoToDetail(id, type) {
				console.log(id, type)
				// if (type == 11) {
				// 	uni.navigateTo({
				// 		url: `/mall_subpages/activitiesList/admissionTicketDetail?id=${id}&type=${type}`
				// 	})
				// 	return;
				// }
				// uni.navigateTo({
				// 	url: `/mall_subpages/activitiesList/admissionTicketDetail?id=${id}&type=${type}`
				// })
			},
		}
	}
</script>
<style lang="scss">
	page {
		background: #F8F8F8;
		min-height: 100%;
	}
</style>

<style lang="scss" scoped>
	.order-detail-page {
		position: relative;
	}

	.header-bg {
		position: absolute;
		z-index: -1;
		top: 0;
		left: 0;
		height: 400rpx;
		width: 100%;
	}

	.header {
		.title {
			padding-top: 50rpx;
			padding-left: 40rpx;
			position: relative;
			z-index: 10;
			color: #FFFFFF;
			font-size: 40rpx;
		}

		.tip {
			font-size: 16rpx;
			padding-left: 10rpx;
		}
	}

	.content {
		z-index: 10;
		min-height: 600rpx;
		background: #FFFFFF;
		border-radius: $uni-border-radius-lg;
		overflow: hidden;

		.title {
			padding: 20rpx 30rpx;
			font-size: 32rpx;
			font-weight: bold;
			font-stretch: normal;
			line-height: 40rpx;
			letter-spacing: 0rpx;
			color: #333333;
			position: relative;

			&:after {
				@include border1px;
				bottom: 0;
				left: 5%;
				width: 90%;
			}
		}
	}

	/* 地址信息 */
	.address-section {
		padding: 30rpx 0;
		background: #fff;
		position: relative;

		.order-content {
			display: flex;
			align-items: center;
		}

		.icon-dizhi {
			flex-shrink: 0;
			display: flex;
			align-items: center;
			justify-content: center;
			width: 90rpx;
			color: #888;
			font-size: 44rpx;
		}

		.cen {
			display: flex;
			flex-direction: column;
			flex: 1;
			font-size: 28rpx;
			color: $font-color-dark;
		}

		.name {
			font-size: 34rpx;
			margin-right: 24rpx;
		}

		.address {
			margin-top: 16rpx;
			margin-right: 20rpx;
			color: $font-color-light;
		}

		.icon-right {
			font-size: 32rpx;
			color: $font-color-light;
			margin-right: 30rpx;
		}

		.a-bg {
			position: absolute;
			left: 5%;
			bottom: 0;
			display: block;
			width: 90%;
			height: 5rpx;
		}

		.wapper {
			display: flex;
			justify-content: center;
			align-items: center;
			padding: 30rpx 0;

			.img {
				image {
					width: 80rpx;
					height: 80rpx;
				}
			}

			.desc {
				padding-left: 20rpx;
				padding-bottom: 6px;
				font-size: 38rpx;
				font-weight: bold;
				color: #333;
			}
		}
	}

	/* 地址信息 end*/
	/* 商品信息 */
	.goods-section {
		margin-top: 16rpx;
		background: #fff;
		padding-bottom: 1px;

		.g-header {
			display: flex;
			align-items: center;
			height: 84rpx;
			padding: 0 30rpx;
			position: relative;
		}

		.logo {
			display: block;
			width: 50rpx;
			height: 50rpx;
			border-radius: 100px;
		}

		.name {
			font-size: 30rpx;
			color: $font-color-base;
			margin-left: 24rpx;
		}

		.g-item {
			display: flex;
			padding: 20rpx 30rpx;

			image {
				flex-shrink: 0;
				display: block;
				width: 160rpx;
				height: 160rpx;
				border-radius: 4rpx;
				background: #F8F8F8;
			}

			.right {
				flex: 1;
				padding-left: 24rpx;
				overflow: hidden;
			}

			.g-title {
				padding: 0;
				font-size: 30rpx;
				color: $font-color-dark;
				@include overEllipsis
			}

			.wapper {
				display: flex;
				justify-content: space-between;
			}

			.spec {
				font-size: 26rpx;
				color: $font-color-light;
				padding-left: 10rpx;

				.number {
					font-size: 26rpx;
					color: $font-color-base;
					margin-left: 20rpx;
				}
			}

			.price {
				margin-bottom: 4rpx;
				font-size: 32rpx;
				color: #498FFF;
				padding-top: 10rpx;
			}

			.step-box {
				position: relative;
			}
		}

		.action-btn {
			width: 160rpx;
			height: 60rpx;
			margin: 0;
			margin-left: 24rpx;
			padding: 0;
			text-align: center;
			line-height: 60rpx;
			font-size: $font-sm + 2rpx;
			color: $font-color-dark;
			background: #fff;
			border-radius: 100px;

			&:after {
				border-radius: 100px;
			}

			&.recom {
				background: #fff9f9;
				color: $base-color;

				&:after {
					border-color: #f7bcc8;
				}
			}
		}

		.price-box {
			display: flex;
			justify-content: space-between;
			padding: 20rpx 30rpx;
			font-size: $font-sm + 2rpx;
			color: $font-color-light;
			border-top: 1px dashed #eee;
			border-bottom: 1px dashed #eee;

			.price {
				font-size: $font-lg;
				color: #498FFF;

				&:before {
					content: '￥';
					font-size: $font-sm;
					color: $base-color;
					margin: 0 2rpx 0 8rpx;
				}
			}
		}
	}

	/* 商品信息 end */
	/* 订单信息 */
	.order-section {
		padding-bottom: 20rpx;
	}

	.qrcode-wap {
		width: 100%;
		display: flex;
		justify-content: center;
	}

	.order-info {
		display: flex;
		flex-direction: column;

		.item {
			display: flex;
			flex-direction: row;
			padding: 10rpx 30rpx;

			.xicon {
				font-size: $uni-font-size-base;
				color: $uni-text-color-grey;
				padding: 10rpx;
			}

			.name,
			.value {
				font-size: $uni-font-size-sm;
				color: #333333;
			}

			.name {
				width: 150rpx;
			}
		}
	}

	/* 订单信息 end*/
</style>